/*  PLUTO JS -Scripting Web Server.
    Copyright (C) 2013 vivek gangadharan

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package pluto.http;

import java.util.HashMap;
import java.util.StringTokenizer;

public class HTTPDefinition {

    private final static HashMap<String, String> mimeTypeMap = new HashMap<>();

    public static class HTTPStatus {

        public static final String OK = "200 OK";
        public static final String PARTIALCONTENT = "206 Partial Content";
        public static final String RANGE_NOT_SATISFIABLE = "416 Requested Range Not Satisfiable";
        public static final String REDIRECT = "301 Moved Permanently";
        public static final String NOTMODIFIED = "304 Not Modified";
        public static final String FORBIDDEN = "403 Forbidden";
        public static final String NOTFOUND = "404 Not Found";
        public static final String BADREQUEST = "400 Bad Request";
        public static final String INTERNALERROR = "500 Internal Server Error";
        public static final String NOTIMPLEMENTED = "501 Not Implemented";
    }

    public static class MIMEType {

        public static final String MIME_PLAINTEXT = "text/plain";
        public static final String MIME_HTML = "text/html";
        public static final String MIME_DEFAULT_BINARY = "application/octet-stream";
        public static final String MIME_XML = "text/xml";
    }

    static {
        StringTokenizer st = new StringTokenizer(
                "css		text/css "
                + "htm		text/html "
                + "html		text/html "
                + "xml		text/xml "
                + "txt		text/plain "
                + "asc		text/plain "
                + "gif		image/gif "
                + "jpg		image/jpeg "
                + "jpeg		image/jpeg "
                + "png		image/png "
                + "mp3		audio/mpeg "
                + "m3u		audio/mpeg-url "
                + "mp4		video/mp4 "
                + "ogv		video/ogg "
                + "flv		video/x-flv "
                + "mov		video/quicktime "
                + "swf		application/x-shockwave-flash "
                + "js		application/javascript "
                + "pdf		application/pdf "
                + "doc		application/msword "
                + "ogg		application/x-ogg "
                + "zip		application/octet-stream "
                + "exe		application/octet-stream "
                + "class	application/octet-stream ");

        while (st.hasMoreTokens()) {
            mimeTypeMap.put(st.nextToken(), st.nextToken());
        }
    }

    public static String getMimeType(String key) {
        return mimeTypeMap.get(key);
    }
}
